﻿using CardMaker.Library.Models;

namespace CardMaker.Library.Pages; 

public partial class MainPage {
    private CardTemplate _cardTemplate = new();
    private bool _isLoading = true;
    private List<string> frameImg;
    private List<CardTemplate> cardTemplates;
    private List<FrameAndCardtemplate> frameAndCardtemplateList=new List<FrameAndCardtemplate>();
    protected override void OnAfterRender(bool firstRender)
    {
        if (!firstRender)
            return;
        Task.Run(async () => {
            //todo 需要做一个初始化页面 目前需要先点击creatcard页面
            await _sideImageStorage.InitializeAsync();

            await _cardTemplateStorage.InitializeAsync();

            await _frameImageStorage.InitializeAsync();
            await _cardImageToUrlService.InitModuleAsync();

            cardTemplates = (List<CardTemplate>)await _cardTemplateService.GetCardTemplatesAsync();//获取模板id为1的模板

            for (int i = 0; i < cardTemplates.Count; i++) {
                frameAndCardtemplateList.Add(new FrameAndCardtemplate(cardTemplates[i],await _createCardService.GetFrameImageAsync(cardTemplates[i])));//获取框图url
            }
            _isLoading = false;

            await InvokeAsync(StateHasChanged);
        });
    }

    private Task OnListViewItemClick(FrameAndCardtemplate arg) {
        throw new NotImplementedException();
    }

    private Task OnListViewItemClick(CardTemplate arg) {
        throw new NotImplementedException();
    }
}

public class FrameAndCardtemplate {
    public CardTemplate cardTemplate;
    public string frmaeUrl;
    public FrameAndCardtemplate(CardTemplate cardTemplate, string frmaeUrl) {
        this.cardTemplate = cardTemplate;
        this.frmaeUrl = frmaeUrl;
    }
}